﻿<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text" />
  <xsl:template match="/">
/*******************************************************************************
** File Name:		     <xsl:value-of select="Schema/@TableName" />Service.cs
** Creator:		       <xsl:value-of select="Schema/@UserName" />
** EMail:            <xsl:value-of select="Schema/@UserEMail" />
** Create date:	     <xsl:value-of select="Schema/@ModifyDate" />
** Latest Modifier:
** Latest Modify date:
** Description:
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Xml;
using System.Reflection;
using System.Configuration;
using ESpace.DALibrary.SqlServer;
using ESpace.DALibrary;

namespace <xsl:value-of select="Schema/@NameSpace" />
{
    public<xsl:if test="Schema/@IsInternal='True'">internal</xsl:if><xsl:if test="Schema/@IsInternal='False'">public</xsl:if> class <xsl:value-of select="Schema/@ClassName" /> : DataAccessBase
    {
       public <xsl:value-of select="Schema/@ClassName" />()
       {
           base.EncryptMethod = Alogrim.SymmProvEnum.<xsl:value-of select="Schema/@EncryptMethod" />;
           base.Key = "<xsl:value-of select="Schema/@Key" />";
           base.IV = "<xsl:value-of select="Schema/@IV" />";
           ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["<xsl:value-of select="Schema/@DBName" />"] == null ? "" : System.Configuration.ConfigurationManager.ConnectionStrings["<xsl:value-of select="Schema/@DBName" />"].ConnectionString;
           base.InitCommand(@"
           INSERT INTO [<xsl:value-of select="Schema/@Owner" />].[<xsl:value-of select="Schema/@TableName" />]
           (<xsl:for-each select="Schema/Columns[IsIdentity='false']">
             [<xsl:value-of select="ColumnName" />]<xsl:if test="position()!=last()">,</xsl:if>
           </xsl:for-each>
           )
           VALUES
           (<xsl:for-each select="Schema/Columns[IsIdentity='false']">
             @<xsl:value-of select="ColumnName" /><xsl:if test="position()!=last()">,</xsl:if>
           </xsl:for-each>
           )
           <xsl:for-each select="Schema/Columns[IsIdentity='true']">
             SET @<xsl:value-of select="ColumnName"/> = @@IDENTITY
           </xsl:for-each>");
       ConfigParameter();
      }
   <xsl:for-each select="Schema/Columns">
      private SqlParameter param<xsl:value-of select="ColumnName" />;
      public <xsl:value-of select="concat(LanguageType,' ',ColumnName)" />
      {
          get
          {
              return (<xsl:value-of select="LanguageType" />)param<xsl:value-of select="ColumnName" />.Value;
          }
          set
          {
              param<xsl:value-of select="ColumnName" />.Value = value;
          }
      }
</xsl:for-each>
      public void ConfigParameter()
      {<xsl:for-each select="Schema/Columns">
        //--------------------------------------------------------
        param<xsl:value-of select="ColumnName" /> = new SqlParameter();
        param<xsl:value-of select="ColumnName" />.ParameterName = "@<xsl:value-of select="ColumnName" />";
        param<xsl:value-of select="ColumnName" />.SqlDbType = <xsl:value-of select="DbType" />;<xsl:if test="IsLengthDef='1'">
          param<xsl:value-of select="ColumnName" />.Size = <xsl:value-of select="MaxLength" />;
        </xsl:if>
        param<xsl:value-of select="ColumnName" />.Precision = <xsl:value-of select="Precision" />;
        param<xsl:value-of select="ColumnName" />.Scale = <xsl:value-of select="Scale" />;
        param<xsl:value-of select="ColumnName" />.Direction = ParameterDirection.<xsl:choose>
          <xsl:when test="IsOutput='false'">Input</xsl:when>
          <xsl:when test="IsOutput='true'">InputOutput</xsl:when>
        </xsl:choose>;
        param<xsl:value-of select="ParameterName" />.Value = DBNull.Value;
        base.sqlComm.Parameters.Add(this.param<xsl:value-of select="ColumnName" />);
      </xsl:for-each>
      }
    }
}
  </xsl:template>
</xsl:stylesheet>

<!--<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text" />
  <xsl:template match="/">

    INSERT INTO [<xsl:value-of select="Schema/@Owner" />].[<xsl:value-of select="Schema/@TableName" />]
    (<xsl:for-each select="Schema/Columns[IsIdentity='false']">
      [<xsl:value-of select="ColumnName" />]<xsl:if test="position()!=last()">,</xsl:if>
    </xsl:for-each>
    )
    VALUES
    (<xsl:for-each select="Schema/Columns[IsIdentity='false']">
      @<xsl:value-of select="ColumnName" /><xsl:if test="position()!=last()">,</xsl:if>
    </xsl:for-each>
    )
    <xsl:for-each select="Schema/Columns[IsIdentity='true']">
      SET @<xsl:value-of select="ColumnName"/> = @@IDENTITY
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>-->